﻿package net.wangit.view.element.component;

import net.wangit.Row;
import net.wangit.context.ActionContext;
import net.wangit.support.AbstractElementWriter;
import net.wangit.view.element.ElementComponent;
import net.wangit.view.element.util.ElementUtil;
import net.wangit.view.util.Html;

public class TextAreaElementWriter extends AbstractElementWriter {

	public TextAreaElementWriter() {
	}

	protected void writeText(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		Html.set(html, ElementUtil.getValueOrDefault(ac, ec, row));
	}

	protected void writeTextWithValue(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		Html.set(html, ElementUtil.getValueOrDefault(ac, ec, row));
		ElementUtil.setHidden(ac, html, ec, row);
	}

	protected void writeControl(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		html.append("<textarea name=\"").append(ElementUtil.getAlias(ec))
				.append("\"");
		Html.setAttribute(html, ElementUtil.resolveCustom(ac, ec, row));
		Html.setTitle(html, ElementUtil.resolveTitle(ac, ec, row));
		Html.setCss(html, ec.getCss(), "E8");
		Html.setStyleWithWidth(html, ec.getWidth());
		Html.setRows(html, ec.getHeight());
		html.append(">");
		Html.set(html, ElementUtil.getValueOrDefault(ac, ec, row));
		html.append("</textarea>");
	}

	protected void writeReadOnlyControl(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		html.append("<textarea name=\"").append(ElementUtil.getAlias(ec))
				.append("\"");
		Html.setAttribute(html, ElementUtil.resolveCustom(ac, ec, row));
		Html.setTitle(html, ElementUtil.resolveTitle(ac, ec, row));
		Html.setCss(html, ec.getCss(), "E8D");
		Html.setStyleWithWidth(html, ec.getWidth());
		Html.setRows(html, ec.getHeight());
		html.append(" readonly>");
		Html.set(html, ElementUtil.getValueOrDefault(ac, ec, row));
		html.append("</textarea>");
	}

	protected void writeDisabledControl(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		html.append("<textarea name=\"").append(ElementUtil.getAlias(ec))
				.append("\"");
		Html.setAttribute(html, ElementUtil.resolveCustom(ac, ec, row));
		Html.setTitle(html, ElementUtil.resolveTitle(ac, ec, row));
		Html.setCss(html, ec.getCss(), "E8D");
		Html.setStyleWithWidth(html, ec.getWidth());
		Html.setRows(html, ec.getHeight());
		html.append(" disabled>");
		Html.set(html, ElementUtil.getValueOrDefault(ac, ec, row));
		html.append("</textarea>");
	}

	protected void writeHidden(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		ElementUtil.setHidden(ac, html, ec, row);
	}
}
